package view.mediator.monster.large_monster
{
	import model.monster.MonsterModel;
	import model.vo.monster.SpVo;
	
	import org.robotlegs.mvcs.StarlingMediator;
	
	import view.component.monster.large_monster.LMVideoEditView;
	import view.event.monster.LMVideoEditViewEvent;
	
	
	/**
	 * LMVideoEditView界面中介
	 * @author £iang
	 * 
	 */	
	public class LMVideoEditViewMediator extends StarlingMediator
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 界面 */
		[Inject]
		public var lMVideoEditView:LMVideoEditView;
		/** monsterModel */
		[Inject]
		public var monsterModel:MonsterModel;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 注册函数 
		 * 
		 */		
		override public function onRegister():void
		{
			addContextListener( LMVideoEditViewEvent.START_EDIT, startEditHandler );
			addContextListener( LMVideoEditViewEvent.START_ADD, startAddHandler );
			addViewListener( LMVideoEditViewEvent.CANCEL, cancelHandler );
			addViewListener( LMVideoEditViewEvent.ENSURE, ensureHandler );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 * 处理请求开始编辑后派发的事件 
		 * @param event 请求开始编辑后派发的事件 
		 * 
		 */		
		protected function startEditHandler( event:LMVideoEditViewEvent ):void
		{
			lMVideoEditView.setInfo( monsterModel.curDealingVideo );
		}
		
		/**
		 * 处理请求开始添加后派发的事件 
		 * @param event 请求开始添加后派发的事件 
		 * 
		 */		
		protected function startAddHandler( event:LMVideoEditViewEvent ):void
		{
			lMVideoEditView.clearInfo();
		}
		
		/**
		 * 处理取消操作后派发的事件 
		 * @param event 取消操作后派发的事件 
		 * 
		 */		
		protected function cancelHandler( event:LMVideoEditViewEvent ):void
		{
			dispatch( event );
		}
		
		/**
		 * 处理请求确认编辑后派发的事件 
		 * @param event 请求确认编辑后派发的事件 
		 * 
		 */		
		protected function ensureHandler( event:LMVideoEditViewEvent ):void
		{
			var editData:SpVo = lMVideoEditView.getEditInfo();
			
			monsterModel.curDealingVideo.name = editData.name;
			monsterModel.curDealingVideo.url = editData.url;
			monsterModel.curDealingVideo.star = editData.star;
			
			if ( monsterModel.curVideoOperation == "edit" )
			{
				dispatch( new LMVideoEditViewEvent(
					LMVideoEditViewEvent.ENSURE_EDIT
				));
			}
			else
			{
				dispatch( new LMVideoEditViewEvent(
					LMVideoEditViewEvent.ENSURE_ADD
				));
			}
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 移除函数 
		 * 
		 */		
		override public function onRemove():void
		{
			removeContextListener( LMVideoEditViewEvent.START_EDIT, startEditHandler );
			removeContextListener( LMVideoEditViewEvent.START_ADD, startAddHandler );
			removeViewListener( LMVideoEditViewEvent.CANCEL, cancelHandler );
			removeViewListener( LMVideoEditViewEvent.ENSURE, ensureHandler );
			super.onRemove();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function LMVideoEditViewMediator()
		{
			super();
		}
	}
}